home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3097 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!rpl
  3. From: rpl@netcom.com (Robert Laudati)
  4. Subject: Output precision
  5. Message-ID: <rplDLKLwK.119@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. Date: Mon, 22 Jan 1996 06:55:32 GMT
  9. Sender: rpl@netcom11.netcom.com
  10.  
  11. It doesn't get too much more basic than this, but I can not
  12. set the precision correctly on output. Here's the sample:
  13.  
  14. #include <stdio.h>
  15. #include <iostream.h>
  16. #include <iomanip.h>
  17.  
  18. int main( int argc, char *argv[])
  19. {
  20.   int    i=0;
  21.   float  x=56.0;
  22.   double y=34.038383999;
  23.  
  24.   i = cout.precision(6);
  25.   printf( "%d %f %lf\n\n", i, x, y );
  26.   cout << i << " " << x << " " << y << endl;
  27.   return 0;
  28. }
  29.  
  30. Which results in:
  31.  
  32. robl@cosmo<216>: test
  33. 6 56.000000 34.038384
  34.  
  35. 6 56 34.0384
  36. robl@cosmo<217>: 
  37.  
  38. I'm running gcc 2.7.1 on Solaris 2.4 - and very confused!
  39.  
  40.  
  41. Rob
  42. --
  43. .........................................................
  44. . Robert P. Laudati        rob_laudati@trimble.com    .
  45. . Trimble Navigation Ltd.       rpl@netcom.com          .     
  46. . P.O. Box 3642                (408) 481-8292 voice    .      
  47. . Sunnyvale, CA 94088           (408) 481-8370 fax      .     
  48. .                                                       .
  49. . These views are not necessarily those of Trimble.     .
  50. .........................................................
  51.